/**
* @author Halon
*/

function GSMSingleton()
{
    this.logger = new Logger('GSM');
    this.scenes = new Array();
}
GSMSingleton.prototype.show = function(sgm)
{
    for( var s in this.scenes)
        this.scenes[s].deactivate();
    sgm.activate();
}
GSMSingleton.prototype.get = function(sgm)
{
    for( var s in this.scenes)
        if (s == sgm)
            return this.scenes[s];
    this.logger.log('Returning new Scene Manager');
    var ss = new SceneGroupManager();
    this.scenes[sgm] = ss;
    return ss;
}

function SceneGroupManager() {
this.logger = new Logger('SGM');
this.logger.log('ctor', 'creating new SGM');
this.masterScenes = new Array();
this.scenes = new Array();
this.active = null;

};
SceneGroupManager.prototype.addScene = function(scene)
{
    this.logger.log('s', 'Adding scene ' + scene);
    $.sfScene.show(scene);
    $.sfScene.hide(scene);
    for (var s in this.scenes)
        if (s === scene)
            return;
    this.scenes.push(scene);
    this.active = this.scenes[0];
}


SceneGroupManager.prototype.addMasterScene = function(scene)
{
    this.logger.log('s','Adding master scene ' + scene);
    $.sfScene.show(scene);
    $.sfScene.hide(scene);
    for (var s in this.masterScenes)
        if (s === scene)
            return;
    this.masterScenes.push(scene);
}

SceneGroupManager.prototype.activate = function()
{
    this.logger.log('s','activating');
    for(var s in this.masterScenes)
        $.sfScene.show(this.masterScenes[s]);
    $.sfScene.show(this.active);
}
SceneGroupManager.prototype.deactivate = function()
{
    this.logger.log('s','deactivating');
    for(var s in this.masterScenes)
        $.sfScene.hide(this.masterScenes[s]);
    $.sfScene.hide(this.active);
}


SceneGroupManager.prototype.showScene = function(scene)
{
    this.logger.log('s','showing ' + scene);
    $.sfScene.hide(this.active);
    this.active = scene;
    $.sfScene.show(this.active);
}

SceneGroupManager.prototype.show = function(id)
{
    this.logger.log('s','showing scene with id: ' + id);
    $.sfScene.hide(this.active);
    this.active = this.scenes[id];
    $.sfScene.show(this.active);
}



var GSM = new GSMSingleton();

CodeRepo.SetReady('SceneManager');
